//
//  RZIMClient.h
//  RZIM
//
//  Created by reyzhang on 2021/7/26.
//  IM即时通讯 客户端工具类 管理消息的收/发

#import <Foundation/Foundation.h>
#import "RZIMConfig.h"
#import "RZIMDefine.h"
#import "RZMessage.h"
#import "RZMessageInfo.h"


#import "RZUserInfo.h"
#import "RZGroupInfo.h"
#import "RZConversation.h"

#import "RZSocketRocketManager.h"
#import "RZSystemSoundPlayer.h"



typedef void(^ErrorBlock)(RZErrorCode nErrorCode, NSString  * _Nullable errorMessage);
#pragma mark - 连接状态监听器

/*!
 连接状态的的监听器
 */
@protocol RZIMConnectionStatusDelegate <NSObject>

/*!
 连接状态的的监听器
 @discussion 如果您设置了消息监听之后，当SDK与服务器的连接状态发生变化时，会回调此方法。
 */
- (void)onRZIMConnectionStatusChanged:(RZConnectionStatus)status;

@end


NS_ASSUME_NONNULL_BEGIN

@interface RZIMClient : NSObject
@property (nonatomic, weak) id<RZIMConnectionStatusDelegate> connectionStatusDelegate; //连接状态变更回调
@property (nonatomic, assign) RZConnectionStatus connectStatus; //连接状态
@property (nonatomic, assign, readonly) RZSDKRunningMode sdkRunningMode; //运行模式
@property (nonatomic, strong) RZUserInfo *userInfo;


/**
 单例， 全局访问入口
 */
+ (instancetype)sharedClient;

/**
 单例释放
 */
+(void)attempDealloc;

/**
 根据Token连接 websocket
 @token 拿到用户登录后的token，用来鉴权
 */
- (void)connectWithToken:(NSString *)token
                 success:(dispatch_block_t)successBlock
                   error:(void (^)(RZIMConnectErrorCode errorCode))errorBlock;

/**
 关闭连接
 */
- (void)disconnect;


/**
 关闭连接，并关闭重连机制。避免因为连接异常，进入无限的重连机制
 */
- (void)disReConnect;


/**
 发送消息
 @content 是对消息内容的封装
 */
- (void)sendMessageWithGroupId:(NSString *)groupId
                   content:(RZMessageContent *)content
                   success:(dispatch_block_t)successBlock
                     error:(ErrorBlock)errorBlock;

/**
 刷新用户信息
 @userInfo 要更新的用户信息
 */
- (void)refreshUserInfo:(RZUserInfo *)userInfo;


#pragma mark - 群组相关
/**
 加入私聊
 @label 标签，分组会话
 */
- (void)joinPrivateChatWithTargetId:(NSString *)tid
                              label:(NSInteger)label
                            success:(void(^)(RZGroupInfo *groupInfo))successBlock
                              error:(ErrorBlock)errorBlock;


/**
 加入私聊,不分组会话
 */
- (void)joinPrivateChatWithTargetId:(NSString *)tid
                            success:(void(^)(RZGroupInfo *groupInfo))successBlock
                              error:(ErrorBlock)errorBlock;



/**
 创建群组
 @label标签，可以用来分组会话
 @uids 加入群组的用户id 数组
 */
- (void)createGroupWithName:(NSString *)name
                   portrait:(NSString *)portrait
                       uids:(NSArray *)uidsList
                      label:(NSInteger)label
                    success:(void(^)(RZGroupInfo *groupInfo))successBlock
                      error:(ErrorBlock)errorBlock;
/**
 创建群组， 不分组会话
 */
- (void)createGroupWithName:(NSString *)name
                   portrait:(NSString *)portrait
                       uids:(NSArray *)uidsList
                    success:(void(^)(RZGroupInfo *groupInfo))successBlock
                      error:(ErrorBlock)errorBlock;


/**
 获取会话列表
 @conversationTypeList 会话类型的数组，需要将 RZConversationType 转为 NSNumber 构建 Array
 @label 标签， 分组会话
 */
- (void)getConversationList:(NSArray<NSNumber*> *)conversationTypeList
                      count:(NSInteger)count
                      label:(NSInteger)label
                    success:(void(^)(NSArray<RZConversation *> *dataSource))successBlock
                      error:(ErrorBlock)errorBlock;


/**
 获取会话列表，不分组会话
 */
- (void)getConversationList:(NSArray<NSNumber*> *)conversationTypeList
                      count:(NSInteger)count
                    success:(void(^)(NSArray<RZConversation *> *dataSource))successBlock
                      error:(ErrorBlock)errorBlock;



/**
 删除会话
 */
- (void)removeConversationWithTargetId:(NSString *)groupId
                               success:(dispatch_block_t)successBlock
                                 error:(ErrorBlock)errorBlock;


/**
 获取会话详情
 */
- (void)getConversationWithTargetId:(NSString *)groupId
                            success:(void(^)(RZConversation *conversation))successBlock
                              error:(ErrorBlock)errorBlock;


#pragma mark - 消息相关

/**
 获取某个会话下的消息
 */
- (void)getHistoryMessageWithTargetId:(NSString *)groupId
                                 page:(NSInteger)pageIndex
                             pageSize:(NSInteger)pageSize
                              success:(void(^)(NSArray<RZMessageInfo *> *dataSource, NSInteger totalPage))successBlock
                                error:(ErrorBlock)errorBlock;



/**
 上传多媒体消息
 */
- (void)sendMediaMessage:(RZMessage *)message
                progress:(void (^)(int progress, RZMessage *progressMessage))progressBlock
            successBlock:(void (^)(RZMessage *successMessage))successBlock
              errorBlock:(void (^)(RZErrorCode nErrorCode, RZMessage *errorMessage))errorBlock;
@end

NS_ASSUME_NONNULL_END
